package com.tdkj.service.exchangerate.impl;

import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.exchangerate.IBeanExchangeRateDao;
import com.tdkj.model.base.BaseEntity;
import com.tdkj.model.exchangerate.BeanExchangeRate;
import com.tdkj.service.BaseService;
import com.tdkj.service.exchangerate.IBeanExchangeRateService;
            
@Component("exchanageRateService")
public class BeanExchangeRateServiceImpl extends BaseService implements IBeanExchangeRateService{
	private  IBeanExchangeRateDao beanExchangeRateDao;
	                              
	@Resource
	public void setBeanExchangeRateDao(IBeanExchangeRateDao beanExchangeRateDao) {
		this.beanExchangeRateDao = beanExchangeRateDao;
	}

	public IBeanExchangeRateDao getBeanExchangeRateDao() {
		return beanExchangeRateDao;
	}

	@Override
	public void updateDiscout(long id, Integer discount) {
		BeanExchangeRate bean = beanExchangeRateDao.findById(id, BeanExchangeRate.class);
		bean.setDiscount(discount);
		beanExchangeRateDao.save(bean);
	}

	@Override
	public void updateGold(long id, Integer value) {
		BeanExchangeRate bean = beanExchangeRateDao.findById(id, BeanExchangeRate.class);
		bean.setGoldcoin(value);
		beanExchangeRateDao.save(bean);
	}

	@Override
	public void updateIntegral(long id, Integer value) {
		BeanExchangeRate bean = beanExchangeRateDao.findById(id, BeanExchangeRate.class);
		bean.setIntegral(value);
		beanExchangeRateDao.save(bean);
	}

	@Override
	public BeanExchangeRate getExchangeRate() {
		BeanExchangeRate bean = null;
		List<BeanExchangeRate> beans = beanExchangeRateDao.findAll(BeanExchangeRate.class);
		if(beans == null || beans.size()<1){
			bean = new BeanExchangeRate();
			bean.setIntegral(10);
			bean.setSilvercoin(1);
			bean.setGoldcoin(10);
			bean.setRmb(1);
			bean.setDiscount(0);
			
			beanExchangeRateDao.save(bean);
		}else{
			bean = beans.get(0);
		}
		return bean;
	}

}
